﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace dogetrader.CryptsyAPI
{
    /**
     * This class is setup in the same structure as Cryptsy's JSON DOGE/BTC data response for easy deserializing using the Json.NET library.  
     */
    class DogeMarketData
    {
        public int success { get; set; }
        //note: it might be also possible to use decorator [JsonProperty(PropertyName = "return")]
        public DMDReturns @return { get; set; }
    }
    class DMDReturns
    {
        public DMDMarkets markets { get; set; }
    }
    class DMDMarkets
    {
        public DMDDoge DOGE { get; set; }
    }
    class DMDDoge
    {
        public string marketid { get; set; }
        public string label { get; set; }
        public double lasttradeprice { get; set; }
        public double volume { get; set; }
        public DateTime lasttradetime { get; set; }
        public string primaryname { get; set; }
        public string primarycode { get; set; }
        public string secondaryname { get; set; }
        public string secondarycode { get; set; }
        public DMDRecentTrade[] recenttrades { get; set; }
        public DMDSellOrder[] sellorders { get; set; }
        public DMDBuyOrder[] buyorders { get; set; }
    }
    class DMDRecentTrade
    {
        public int id { get; set; }
        public DateTime time { get; set; }
        public double price { get; set; }
        public double quantity { get; set; }
        public double total { get; set; }
    }
    class DMDSellOrder
    {
        public double price { get; set; }
        public double quantity { get; set; }
        public double total { get; set; }
    }
    class DMDBuyOrder
    {
        public double price { get; set; }
        public double quantity { get; set; }
        public double total { get; set; }
    }

    /**
     * A DOGE trade comparer for use with HashSet.  The transaction ID is used for the comparison.  
     */
    class DMDRecentTradeComparer : IEqualityComparer<DMDRecentTrade>
    {
        public bool Equals(DMDRecentTrade trade1, DMDRecentTrade trade2)
        {
            return (trade1.id.CompareTo(trade2.id) == 0);
        }

        public int GetHashCode(DMDRecentTrade trade)
        {
            return trade.id;
        }
    }
}
